﻿using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Windows.Forms;

namespace HML.Design
{
    /// <summary>
    ///  SingleAccordion节点集合属性编辑器
    /// </summary>
    internal class SingleAccordionNodeCollectionEditor : CollectionEditor
    {
        protected override string HelpTopic
        {
            get { return "HML.Design.SingleAccordionNodeCollectionEditor"; }
        }

        public SingleAccordionNodeCollectionEditor() : base(typeof(SingleAccordionNodeCollection))
        {

        }

        protected override CollectionEditor.CollectionForm CreateCollectionForm()
        {
            return (CollectionEditor.CollectionForm)new SingleAccordionNodeCollectionEditor.SingleAccordionNodeCollectionEditorForm((CollectionEditor)this);
        }

        /// <summary>
        ///  SingleAccordion集合属性编辑窗体
        /// </summary>
        protected class SingleAccordionNodeCollectionEditorForm : CollectionForm
        {
            #region 字段

            private SingleAccordionNodeCollectionEditor editor;

            private System.Windows.Forms.Label tvControlLabel;
            private System.Windows.Forms.Label pgControllabel;
            public System.Windows.Forms.TreeView tvControl;
            private System.Windows.Forms.Button btnExpand;
            private System.Windows.Forms.Button btnCollapse;
            private System.Windows.Forms.Button btnMoveUp;
            private System.Windows.Forms.Button btnMoveDown;
            private System.Windows.Forms.Button btnDelete;
            private System.Windows.Forms.Button btnOk;
            private System.Windows.Forms.Button btnCancel;
            private System.Windows.Forms.PropertyGrid pgControl;
            private System.Windows.Forms.Button btnAddRootLabel;
            private System.Windows.Forms.Button btnAddRootCategory;
            private System.Windows.Forms.Button btnAddRootContent;
            private System.Windows.Forms.Button btnAddChildContent;

            #endregion

            public SingleAccordionNodeCollectionEditorForm(CollectionEditor editor) : base(editor)
            {
                this.editor = (SingleAccordionNodeCollectionEditor)editor;

                InitializeComponent();

                this.tvControl.AfterSelect += this.tvControl_AfterSelect;
                this.pgControl.PropertyValueChanged += pgControl_PropertyValueChanged;
                this.btnAddRootLabel.Click += this.BtnAddRootLabel_Click;
                this.btnAddRootCategory.Click += this.btnAddRootCategory_click;
                this.btnAddRootContent.Click += this.btnAddRootContent_click;
                this.btnAddChildContent.Click += this.BtnAddChildContent_Click;
                this.btnExpand.Click += this.BtnExpand_Click;
                this.btnCollapse.Click += this.BtnCollapse_Click;
                this.btnMoveUp.Click += this.btnMoveUp_Click;
                this.btnMoveDown.Click += this.btnMoveDown_Click;
                this.btnDelete.Click += this.btnDelete_click;
                this.btnOk.Click += this.BtnOk_Click;

            }

            #region 重写方法

            protected override void OnEditValueChanged()
            {

                if (this.EditValue == null)
                    return;

                this.pgControl.Site = (ISite)new PropertyGridSite((System.IServiceProvider)this.Context, (IComponent)this.pgControl);
                this.tvControl.Nodes.Clear();

                foreach (SingleAccordionNode singleaccordionnode in this.Items)
                {
                    SingleAccordionNode new_singleaccordionnode = singleaccordionnode.Copy();
                    TreeNode tree_node = new TreeNode() { Text = new_singleaccordionnode.Text, Tag = new_singleaccordionnode };
                    this.tvControl.Nodes.Add(tree_node);

                    if (singleaccordionnode is SingleAccordionCategoryNode)
                    {
                        SingleAccordionCategoryNode category = (SingleAccordionCategoryNode)singleaccordionnode;
                        foreach (SingleAccordionContentNode content in category.Childrens)
                        {
                            SingleAccordionNode new_content = content.Copy();
                            tree_node.Nodes.Add(new TreeNode() { Text = new_content.Text, Tag = new_content });
                        }
                    }
                }

                this.tvControl.ExpandAll();
            }

            #endregion

            #region 私有方法

            private void InitializeComponent()
            {
                this.tvControl = new System.Windows.Forms.TreeView();
                this.tvControlLabel = new System.Windows.Forms.Label();
                this.pgControllabel = new System.Windows.Forms.Label();
                this.btnExpand = new System.Windows.Forms.Button();
                this.btnCollapse = new System.Windows.Forms.Button();
                this.btnMoveUp = new System.Windows.Forms.Button();
                this.btnMoveDown = new System.Windows.Forms.Button();
                this.btnDelete = new System.Windows.Forms.Button();
                this.btnOk = new System.Windows.Forms.Button();
                this.btnCancel = new System.Windows.Forms.Button();
                this.pgControl = new System.Windows.Forms.PropertyGrid();
                this.btnAddRootLabel = new System.Windows.Forms.Button();
                this.btnAddRootCategory = new System.Windows.Forms.Button();
                this.btnAddRootContent = new System.Windows.Forms.Button();
                this.btnAddChildContent = new System.Windows.Forms.Button();
                this.SuspendLayout();
                // 
                // tvControlLabel
                // 
                this.tvControlLabel.AutoSize = true;
                this.tvControlLabel.Location = new System.Drawing.Point(8, 8);
                this.tvControlLabel.Name = "label1";
                this.tvControlLabel.Size = new System.Drawing.Size(170, 18);
                this.tvControlLabel.TabIndex = 1;
                this.tvControlLabel.Text = "选择要编辑的节点：";
                // 
                // pgControllabel
                // 
                this.pgControllabel.AutoSize = true;
                this.pgControllabel.Location = new System.Drawing.Point(408, 8);
                this.pgControllabel.Name = "label2";
                this.pgControllabel.Size = new System.Drawing.Size(62, 18);
                this.pgControllabel.TabIndex = 2;
                this.pgControllabel.Text = "属性：";
                // 
                // tvControl
                // 
                this.tvControl.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                | System.Windows.Forms.AnchorStyles.Left)));
                this.tvControl.HideSelection = false;
                this.tvControl.Location = new System.Drawing.Point(11, 29);
                this.tvControl.Name = "tvControl";
                this.tvControl.Size = new System.Drawing.Size(304, 395);
                this.tvControl.TabIndex = 0;
                // 
                // btnExpand
                // 
                this.btnExpand.Location = new System.Drawing.Point(321, 30);
                this.btnExpand.Name = "btnExpand";
                this.btnExpand.Size = new System.Drawing.Size(95, 35);
                this.btnExpand.TabIndex = 5;
                this.btnExpand.Text = "展开";
                this.btnExpand.UseVisualStyleBackColor = true;
                this.btnExpand.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
                this.btnExpand.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
                this.btnExpand.Image = HML.SingleAccordionResources.SingleAccordionNodeCollectionEditorForm_btnExpand;
                // 
                // btnCollapse
                // 
                this.btnCollapse.Location = new System.Drawing.Point(321, 75);
                this.btnCollapse.Name = "btnCollapse";
                this.btnCollapse.Size = new System.Drawing.Size(95, 35);
                this.btnCollapse.TabIndex = 6;
                this.btnCollapse.Text = "折叠";
                this.btnCollapse.UseVisualStyleBackColor = true;
                this.btnCollapse.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
                this.btnCollapse.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
                this.btnCollapse.Image = HML.SingleAccordionResources.SingleAccordionNodeCollectionEditorForm_btnCollapse;
                // 
                // btnMoveUp
                // 
                this.btnMoveUp.Location = new System.Drawing.Point(321, 120);
                this.btnMoveUp.Name = "btnMoveUp";
                this.btnMoveUp.Size = new System.Drawing.Size(95, 35);
                this.btnMoveUp.TabIndex = 5;
                this.btnMoveUp.Text = "向上移";
                this.btnMoveUp.UseVisualStyleBackColor = true;
                this.btnMoveUp.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
                this.btnMoveUp.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
                this.btnMoveUp.Image = HML.SingleAccordionResources.SingleAccordionNodeCollectionEditorForm_moveUpButton;
                // 
                // btnMoveDown
                // 
                this.btnMoveDown.Location = new System.Drawing.Point(321, 165);
                this.btnMoveDown.Name = "btnMoveDown";
                this.btnMoveDown.Size = new System.Drawing.Size(95, 35);
                this.btnMoveDown.TabIndex = 6;
                this.btnMoveDown.Text = "向下移";
                this.btnMoveDown.UseVisualStyleBackColor = true;
                this.btnMoveDown.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
                this.btnMoveDown.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
                this.btnMoveDown.Image = HML.SingleAccordionResources.SingleAccordionNodeCollectionEditorForm_moveDownButton;
                // 
                // btnDelete
                // 
                this.btnDelete.Location = new System.Drawing.Point(321, 210);
                this.btnDelete.Name = "btnDelete";
                this.btnDelete.Size = new System.Drawing.Size(95, 35);
                this.btnDelete.TabIndex = 7;
                this.btnDelete.Text = "删除";
                this.btnDelete.UseVisualStyleBackColor = true;
                this.btnDelete.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
                this.btnDelete.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
                this.btnDelete.Image = HML.SingleAccordionResources.SingleAccordionNodeCollectionEditorForm_btnDelete;
                // 
                // btnOk
                // 
                this.btnOk.Location = new System.Drawing.Point(450, 515);
                this.btnOk.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
                this.btnOk.Name = "btnOk";
                this.btnOk.Size = new System.Drawing.Size(120, 45);
                this.btnOk.TabIndex = 8;
                this.btnOk.Text = "确定";
                this.btnOk.UseVisualStyleBackColor = true;
                this.btnOk.DialogResult = DialogResult.OK;
                // 
                // btnCancel
                // 
                this.btnCancel.Location = new System.Drawing.Point(580, 515);
                this.btnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
                this.btnCancel.Name = "btnCancel";
                this.btnCancel.Size = new System.Drawing.Size(130, 45);
                this.btnCancel.TabIndex = 9;
                this.btnCancel.Text = "取消";
                this.btnCancel.UseVisualStyleBackColor = true;
                this.btnCancel.DialogResult = DialogResult.Cancel;
                // 
                // pgControl
                // 
                this.pgControl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                | System.Windows.Forms.AnchorStyles.Left)
                | System.Windows.Forms.AnchorStyles.Right)));
                this.pgControl.Location = new System.Drawing.Point(421, 29);
                this.pgControl.Name = "pgControl";
                this.pgControl.Size = new System.Drawing.Size(304, 440);
                this.pgControl.TabIndex = 10;// 
                // btnAddRootLabel
                // 
                this.btnAddRootLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
                this.btnAddRootLabel.Location = new System.Drawing.Point(12, 439);
                this.btnAddRootLabel.Name = "btnAddRootLabel";
                this.btnAddRootLabel.Size = new System.Drawing.Size(140, 35);
                this.btnAddRootLabel.TabIndex = 3;
                this.btnAddRootLabel.Text = "添加根（标签）";
                this.btnAddRootLabel.UseVisualStyleBackColor = true;
                this.btnAddRootLabel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
                this.btnAddRootLabel.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
                this.btnAddRootLabel.Image = HML.SingleAccordionResources.SingleAccordionNodeCollectionEditorForm_btnAddRootLabel;

                // 
                // btnAddRootCategory
                // 
                this.btnAddRootCategory.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
                this.btnAddRootCategory.Location = new System.Drawing.Point(12, 485);
                this.btnAddRootCategory.Name = "btnAddRootCategory";
                this.btnAddRootCategory.Size = new System.Drawing.Size(140, 35);
                this.btnAddRootCategory.TabIndex = 3;
                this.btnAddRootCategory.Text = "添加根（类别）";
                this.btnAddRootCategory.UseVisualStyleBackColor = true;
                this.btnAddRootCategory.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
                this.btnAddRootCategory.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
                this.btnAddRootCategory.Image = HML.SingleAccordionResources.SingleAccordionNodeCollectionEditorForm_btnAddRootCategory;
                // 
                // btnAddRootContent
                // 
                this.btnAddRootContent.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
                this.btnAddRootContent.Location = new System.Drawing.Point(12, 531);
                this.btnAddRootContent.Name = "btnAddRootContent";
                this.btnAddRootContent.Size = new System.Drawing.Size(140, 35);
                this.btnAddRootContent.TabIndex = 4;
                this.btnAddRootContent.Text = "添加根（内容）";
                this.btnAddRootContent.UseVisualStyleBackColor = true;
                this.btnAddRootContent.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
                this.btnAddRootContent.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
                this.btnAddRootContent.Image = HML.SingleAccordionResources.SingleAccordionNodeCollectionEditorForm_btnAddRootContent;
                // 
                // btnAddChildContent
                // 
                this.btnAddChildContent.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
                this.btnAddChildContent.Enabled = false;
                this.btnAddChildContent.Location = new System.Drawing.Point(178, 439);
                this.btnAddChildContent.Name = "btnAddChildContent";
                this.btnAddChildContent.Size = new System.Drawing.Size(140, 35);
                this.btnAddChildContent.TabIndex = 11;
                this.btnAddChildContent.Text = "添加子（内容）";
                this.btnAddChildContent.UseVisualStyleBackColor = true;
                this.btnAddChildContent.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
                this.btnAddChildContent.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
                this.btnAddChildContent.Image = HML.SingleAccordionResources.SingleAccordionNodeCollectionEditorForm_btnAddChildContent;
                // 
                // SingleAccordionNodeCollectionForm
                // 
                this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 18F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(736, 580);
                this.Controls.Add(this.pgControllabel);
                this.Controls.Add(this.tvControlLabel);
                this.Controls.Add(this.tvControl);
                this.Controls.Add(this.pgControl);
                this.Controls.Add(this.btnExpand);
                this.Controls.Add(this.btnCollapse);
                this.Controls.Add(this.btnMoveUp);
                this.Controls.Add(this.btnMoveDown);
                this.Controls.Add(this.btnDelete);
                this.Controls.Add(this.btnAddRootLabel);
                this.Controls.Add(this.btnAddRootCategory);
                this.Controls.Add(this.btnAddRootContent);
                this.Controls.Add(this.btnAddChildContent);
                this.Controls.Add(this.btnCancel);
                this.Controls.Add(this.btnOk);
                this.MaximizeBox = false;
                this.MinimizeBox = false;
                this.MinimumSize = new System.Drawing.Size(752, 566);
                this.Name = "SingleAccordionNodeCollectionForm";
                this.ShowIcon = false;
                this.ShowInTaskbar = false;
                this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
                this.Text = "SingleAccordionNode编辑器";
                this.ResumeLayout(false);
                this.PerformLayout();

            }

            /// <summary>
            /// 选中节点更改
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void tvControl_AfterSelect(object sender, TreeViewEventArgs e)
            {
                this.pgControl.SelectedObject = this.tvControl.SelectedNode.Tag;
                this.btnAddChildContent.Enabled = (this.pgControl.SelectedObject is SingleAccordionCategoryNode);
            }

            /// <summary>
            /// 属性面板值更改
            /// </summary>
            /// <param name="s"></param>
            /// <param name="e"></param>
            private void pgControl_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
            {
                if (e.ChangedItem.PropertyDescriptor.Name == "Text" && this.tvControl.SelectedNode != null)
                {
                    if (this.tvControl.SelectedNode.Tag.GetType() == typeof(SingleAccordionCategoryNode))
                    {
                        this.tvControl.SelectedNode.Text = ((SingleAccordionCategoryNode)this.tvControl.SelectedNode.Tag).Text;
                    }
                    else
                    {
                        this.tvControl.SelectedNode.Text = ((SingleAccordionContentNode)this.tvControl.SelectedNode.Tag).Text;
                    }
                }
            }

            /// <summary>
            /// 添加标签节点
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void BtnAddRootLabel_Click(object sender, EventArgs e)
            {
                SingleAccordionLabelNode label = new SingleAccordionLabelNode() { Text = "标签" + (this.tvControl.Nodes.Count + 1).ToString() };
                TreeNode category_node = new TreeNode() { Text = label.Text, Tag = label };
                this.tvControl.Nodes.Add(category_node);
                this.tvControl.SelectedNode = category_node;
            }

            /// <summary>
            /// 添加根类别节点
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void btnAddRootCategory_click(object sender, EventArgs e)
            {
                SingleAccordionCategoryNode category = new SingleAccordionCategoryNode() { Text = "类别" + (this.tvControl.Nodes.Count + 1).ToString() };
                TreeNode category_node = new TreeNode() { Text = category.Text, Tag = category };
                this.tvControl.Nodes.Add(category_node);
                this.tvControl.SelectedNode = category_node;
            }

            /// <summary>
            /// 添加根内容节点
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void btnAddRootContent_click(object sender, EventArgs e)
            {
                SingleAccordionContentNode content = new SingleAccordionContentNode() { Text = "内容" + (this.tvControl.Nodes.Count + 1).ToString() };
                TreeNode content_node = new TreeNode() { Text = content.Text, Tag = content };
                this.tvControl.Nodes.Add(content_node);
                this.tvControl.SelectedNode = content_node;
            }

            /// <summary>
            /// 添加子内容节点
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void BtnAddChildContent_Click(object sender, EventArgs e)
            {
                if (this.tvControl.SelectedNode != null)
                {
                    if (this.tvControl.SelectedNode.Tag.GetType() == typeof(SingleAccordionCategoryNode))
                    {
                        SingleAccordionContentNode content = new SingleAccordionContentNode() { Text = "内容" + (this.tvControl.SelectedNode.Nodes.Count + 1).ToString() };
                        TreeNode content_node = new TreeNode() { Text = content.Text, Tag = content };
                        this.tvControl.SelectedNode.Nodes.Add(content_node);
                        this.tvControl.SelectedNode.Expand();
                    }
                }
            }

            /// <summary>
            /// 展开所有节点
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void BtnExpand_Click(object sender, EventArgs e)
            {
                for (int i = 0; i < this.tvControl.Nodes.Count; i++)
                {
                    this.tvControl.Nodes[i].Expand();
                }
            }

            /// <summary>
            /// 折叠所有节点
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void BtnCollapse_Click(object sender, EventArgs e)
            {
                for (int i = 0; i < this.tvControl.Nodes.Count; i++)
                {
                    this.tvControl.Nodes[i].Collapse();
                }
            }

            /// <summary>
            /// 上移选中节点
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void btnMoveUp_Click(object sender, EventArgs e)
            {
                if (this.tvControl.SelectedNode != null)
                {
                    TreeNodeCollection list = (this.tvControl.SelectedNode.Level == 0) ? this.tvControl.Nodes : this.tvControl.SelectedNode.Parent.Nodes;
                    int index = list.IndexOf(this.tvControl.SelectedNode);
                    if (index > 0)
                    {
                        TreeNode node = list[index];
                        list.Remove(node);
                        list.Insert(index - 1, node);
                        this.tvControl.SelectedNode = node;
                    }
                }
            }

            /// <summary>
            /// 下移选中节点
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void btnMoveDown_Click(object sender, EventArgs e)
            {
                if (this.tvControl.SelectedNode != null)
                {
                    TreeNodeCollection list = (this.tvControl.SelectedNode.Level == 0) ? this.tvControl.Nodes : this.tvControl.SelectedNode.Parent.Nodes;
                    int index = list.IndexOf(this.tvControl.SelectedNode);
                    if (index < list.Count - 1)
                    {
                        TreeNode node = list[index];
                        list.Remove(node);
                        list.Insert(index + 1, node);
                        this.tvControl.SelectedNode = node;
                    }
                }
            }

            /// <summary>
            /// 移除选中节点
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void btnDelete_click(object sender, EventArgs e)
            {
                if (this.tvControl.SelectedNode != null)
                {
                    TreeNodeCollection list = (this.tvControl.SelectedNode.Level == 0) ? this.tvControl.Nodes : this.tvControl.SelectedNode.Parent.Nodes;
                    list.Remove(this.tvControl.SelectedNode);
                }
                if (this.tvControl.SelectedNode == null)
                {
                    this.pgControl.SelectedObject = null;
                    this.btnAddChildContent.Enabled = false;
                }
            }

            /// <summary>
            /// 确认修改
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void BtnOk_Click(object sender, EventArgs e)
            {
                object[] objArray = new object[this.tvControl.Nodes.Count];
                for (int i = 0; i < this.tvControl.Nodes.Count; i++)
                {
                    objArray[i] = (SingleAccordionNode)this.tvControl.Nodes[i].Tag;
                    for (int k = 0; k < this.tvControl.Nodes[i].Nodes.Count; k++)
                    {
                        SingleAccordionContentNode content = (SingleAccordionContentNode)this.tvControl.Nodes[i].Nodes[k].Tag;
                        ((SingleAccordionCategoryNode)objArray[i]).Childrens.Add(content);
                    }
                }
                this.Items = objArray;
                this.tvControl.Dispose();
                this.tvControl = (TreeView)null;
            }

            #endregion

            /// <summary>
            /// 定义一种检索服务对象的机制，服务对象是为其他对象提供自定义支持的对象。
            /// </summary>
            private class PropertyGridSite : ISite, System.IServiceProvider
            {
                private System.IServiceProvider sp;
                private bool inGetService;

                private IComponent comp;
                public IComponent Component
                {
                    get { return this.comp; }
                }

                public IContainer Container
                {
                    get { return (IContainer)null; }
                }

                public bool DesignMode
                {
                    get { return false; }
                }

                public string Name
                {
                    get { return (string)null; }
                    set { }
                }

                public PropertyGridSite(System.IServiceProvider sp, IComponent comp)
                {
                    this.sp = sp;
                    this.comp = comp;
                }

                public object GetService(System.Type t)
                {
                    if (!this.inGetService)
                    {
                        if (this.sp != null)
                        {
                            try
                            {
                                this.inGetService = true;
                                return this.sp.GetService(t);
                            }
                            finally
                            {
                                this.inGetService = false;
                            }
                        }
                    }
                    return (object)null;
                }
            }

        }

    }

}
